// 渲染语法树
import { isValidKey } from "../../utils";
import { MNode } from "../mnodes";
import MTreeWalker from "../tree_walker";
import HtmlGenerator from "./html_generator";

class MarkdownRender {
  render (mnode: MNode): string {
    const htmlGenerator = new HtmlGenerator();
    const walker = new MTreeWalker(mnode);

    let buffer = '';
    let current: {mnode: MNode, close: boolean} | null;
    while (current = walker.next()) {
      console.log(current)
      if (isValidKey<HtmlGenerator>(current.mnode.type, htmlGenerator)) {
        buffer = htmlGenerator[current.mnode.type](buffer, current.mnode, current.close) || '';
      }
    }
    return buffer;
  }
}

export default MarkdownRender;